<template>
  <div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane v-for="tag in tags" :key="tag" :label="$t(tag)" :name="tag">
        <router-view />
      </el-tab-pane>
    </el-tabs>
    <ky-table
      ref="table"
      :getData="tagName == '添加' ? getProductHostsAddList : getAgentList"
      :showSelect="showSelect"
      :search_data="search_data"
    >
      <template v-slot:table-action>
        <el-button
          class="kylin-item-button"
          v-if="tagName !== '添加'"
          :disabled="$refs.table && $refs.table.selectRow.ids.length == 0"
          >{{ $t("patch.delete_selected") }}</el-button
        >
        <el-button
          class="kylin-item-button"
          v-else
          :disabled="$refs.table && $refs.table.selectRow.ids.length == 0"
          >{{ $t("patch.add_selected") }}</el-button
        >
        <el-button class="kylin-item-button">{{ $t("export") }}</el-button>
      </template>
      <template v-slot:table>
        <el-table-column :label="$t('system.ip_address')">
          <template slot-scope="scope">
            {{ scope.row.ip }}
          </template>
        </el-table-column>
        <el-table-column
          prop="operating_system"
          :label="$t('patch.system_info')"
        >
        </el-table-column>
        <el-table-column prop="version" :label="$t('system.system_version')">
        </el-table-column>
        <el-table-column prop="architecture" :label="$t('system.architecture')">
        </el-table-column>
      </template>
    </ky-table>
  </div>
</template>

<script>
import { getAgentList } from "@/api/system";
import { getProductHostsAddList } from "@/api/patch";
import kyTable from "@/components/KyTable";
export default {
  components: {
    kyTable,
  },
  data() {
    return {
      search_data: {
        name: {
          name: "system.ip_address",
          type: "text",
        },
        system_info: {
          name: "patch.system_info",
          type: "select",
          items: [],
        },
        os_version: {
          name: "patch.os_version",
          type: "select",
          items: [],
        },
        architecture: {
          name: "system.architecture",
          type: "select",
          items: [],
        },
      },
      showSelect: true,
      tags: ["patch.list_with_delete", "add"],
      activeName: "patch.list_with_delete",
      tagName: "",

      table: {
        size: 20,
        total: 0,
        currentPage: 1,
        tableData: [],
        loading: false,
      },
    };
  },
  methods: {
    getAgentList,
    getProductHostsAddList,
    handleClick(e) {
      this.tagName = e.label;
      this.$nextTick(() => {
        this.$refs.table.loadData();
      });
    },
  },
};
</script>

<style>
</style>